package com.ruoyi.classinfo.service.impl;

import com.ruoyi.classinfo.domain.Rewardqk;
import com.ruoyi.classinfo.mapper.CMapper;
import com.ruoyi.classinfo.mapper.RewardqkMapper;
import com.ruoyi.classinfo.mapper.StMapper;
import com.ruoyi.classinfo.service.IRewardqkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class RewardqkServiceImpl implements IRewardqkService {
    @Autowired
    private RewardqkMapper rewardqkMapper;

    @Autowired
    private CMapper classMapper;

    @Autowired
    private StMapper stuInfoMapper;

    @Override
    public List<Rewardqk> selectRewardListByTeacher(String teacherId, Rewardqk rewardqk) {
        // 1. 根据工号查询班主任所带班级
        Integer cid = classMapper.selectCidByTeacherId(teacherId);
//        System.out.println(cid);
        if (cid == null) {
            return Collections.emptyList();
        }

        // 2. 查询该班级所有学生的学号
        List<String> studentIds = stuInfoMapper.selectStudentIdsByCid(cid);
//        for (String studentId : studentIds)
//            System.out.println(studentId);
        if (studentIds.isEmpty()) {
            return Collections.emptyList();
        }

        // 3. 查询这些学生的获奖信息
        return rewardqkMapper.selectRewardsByStudentIds(studentIds, rewardqk);
    }
}
